home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / vgaintro.zip / VGAINTRO.TXT < prev   
Text File  |  1991-07-30  |  6KB  |  116 lines

  1.      Oh well, might as well write a text file on this since I'd be explaining 
  2. this to more than one person sooner or later.  Here goes -
  3.  
  4.  
  5.                      Writing (Graphic) VGA Intros/Loaders
  6.                                      By
  7.                                 Fred Nietzche
  8.                                   07/30/91
  9.  
  10.  
  11.      I'm assuming that you don't understand the concept of video memory, so 
  12. I'll start off from the basics then.  Video memory is defined (for our own 
  13. purposes) as the memory that the video board scans in determining what signals
  14. (analog) to send to the monitor.  In graphics mode, the segment of the location
  15. of this is determined by what type of video mode you are on -
  16. VGA/EGA modes = $A000 ($=hex), CGA modes = $B800, and Herc = $B000.  The
  17. offsets always start off at $0.
  18.  
  19.      Now, what type of organization are the pixels (since we're in graphics 
  20. mode) stored in?  Because of the simplicity of Mode $13 (320x200x256), most
  21. VGA intros are written using this.  I'm not about to go ahead and explain to
  22. you the other VGA modes dealing in the color planes, EGA/VGA registers,etc in
  23. the higher resolution modes, there are a couple of good books out there that
  24. can handle those of you interested in that.  Try your local bookstores and look 
  25. for Power Graphics Programming by Michael Abrash, which contains his articles 
  26. about higher resolution VGA programming from Programmer's Journal.  HIGHLY 
  27. recommendable.  In any case, in this mode, each pixel on the screen 
  28. corresponds to exactly 1 byte on the video memory.  For example, location
  29. (0,0) = Mem[$A000:0], (1,0) = Mem[$A000:1], (2,0) = Mem[A000:2], and so on.
  30. Fairly easy eh?  Because the memory map is linear, the next line would just be
  31. the next byte AFTER the previous line's last pixel.  For example, location
  32. (0,319) = Mem[$A000:319], AND THEN location (1,0) = Mem[$A000:320].  And the 
  33. formula for determining the video memory location is
  34.  
  35.      Video Mem Offset = YPos*320 + XPos
  36.  
  37.      The actual color of the byte values stored in the video memory is
  38. flexible and can be changed to any color of the 256,000 palette of the VGA.
  39. This can be accomplished by altering the VGA Video DAC registers at port
  40. addresses $3C6 through $3C9.  To read the current settings, set the Table
  41. Read Index (port $3C7) to the color value you want, and then read the three
  42. values from the Table Data Register (port $3C9) (one each for Red, Green, and
  43. Blue).  Once three values have been read from that port, the current read
  44. index is incremented by one and the next three 6 bit (range of 2^6, or 0 to 63)
  45. values read are for the next color value.  Writing the to the Video DAC is
  46. similar, except the Table Write Index is port $3C8.  Again, after writing
  47. three successive 6 bit values to the Table Data Registers increments the Write
  48. Index by one.  By the way, all the reference information about the Video DAC's
  49. can be obtained from any EGA/VGA reference book.  I recommend getting
  50. Advanced Programmer's Guide to the EGA/VGA by George Sutty and Steve Blair.
  51.  
  52.      Waiting for the vertical retrace start signal before updating the video
  53. memory is the key to smooth animation (with a quick memory update too of
  54. course).  The idea is to have the screen changes "pop up" before your eyes, and
  55. to do this, you need to make your changes just before the the screen trace
  56. of the video memory occurs.  For this reason, updating the video memory had
  57. better fast enough, and generally this is the part done in assembly.  The
  58. important port and bit locations, and a sample implementation are as follows:
  59.  
  60.        In Pascal:
  61.  
  62.          Repeat Until (Port[$3DA] And $08) = 0;
  63.          Repeat Until (Port[$3DA] And $08) <> 0;
  64.  
  65.        And in Assembly:
  66.  
  67.                    MOV   DX,3DAh
  68.          Wait:     IN    AL,DX
  69.                    TEST  AL,08h
  70.                    JZ    Wait
  71.          Retr:     IN    AL,DX
  72.                    TEST  AL,08h
  73.                    JNZ   Retr
  74.  
  75.  
  76.      And finally, how to get the characters on the screen.  I used the old
  77. character set that's stored in BIOS because it saves time and space (instead
  78. of capturing a graphical message).  The memory address for this is
  79. $F000:$FA6E.  Because the character set is 8 bits by 8 bits, each character
  80. takes up 8 bytes, each byte representing a horizontal slice of the character.
  81. It's really not that confusing after fiddling around with it.
  82.  
  83.      There's also the special effect that palette cycling can do.  For
  84. example, the color bars seen on Amiga and ST programs, although on the IBM,
  85. it's more laborous.  What you do is simply fill each and every horizontal line
  86. along the width of the movement of the bars with a separate color value.
  87. Then blank out (with whatever color you desire) all of those values using the
  88. DAC registers.  To move the bars, just change the color of the values that
  89. need to be blanked out and the ones that need to be "filled in" with the bar
  90. colors (again, through the DAC registers).  That's about it.  You may want to
  91. make the movement of the bars in some pattern, like in the motion of a sine
  92. function for effects.
  93.  
  94.      Another neat idea that palette cycling can accomplish is a shifting
  95. checkerboard.  This one is a little bit more difficult, and I'll let you go
  96. and figure it out on your own.
  97.  
  98.      That's all there is to it in terms of the basics and effects.  I wrote
  99. for myself a screen capturing TSR (very crude, but what it does is dump the
  100. video memory and palette to a file, and that's all I need.  I couldn't find
  101. any PD programs which stored their captured screens in this format,
  102. surprisingly!) to add painted pictures to the loaders, so that may be
  103. something you might want to pursue for yourself.  Compress the executable
  104. you've just created and you're done.
  105.  
  106.      Oh, I've included some sample intros (of my own board) with the ZIP.
  107. I haven't really optimized them fully, but they'll do.  And the TDT/TRSI logo
  108. was captured from one of their loaders.  I've got to admit, they've got some
  109. nice artists working over there.
  110.  
  111.      About a good five minutes of reading eh?  Hope it was some help...
  112.  
  113.  
  114. No greets, just trying to advertise my board around more..  Give it a ring.
  115. CenterPoint! BBS (301) 309-0144, 9600+ only, Sysop - Fred Nietzche.
  116.